Passed
Push — master ( 097df7...bb6e1a )
by Night
01:18
created

stringFuncs.getKeywords   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
/** global: UB */
2
3
4
5
var stringFuncs = {
6
	
7
	// conversion
8
	toAcronym: function(smartCase = true){
9
		var word = this;
10
		// 3D Engine > 3DE
11
		// Home loan > HL
12
		
13
		if (smartCase){
14
			word = word.toSmartCase();
15
		}
16
		
17
		// collect upper case
18
		var chars = [];
19
		for (var c = 0, cl = word.length;c<cl;c++){
20
			var ch = word.charAt(c);
21
			if (ch.isAlphabet() && ch == ch.toUpperCase()) {
22
				chars.push(ch);
23
			}
24
		}
25
		return chars.join("");
26
	},
27
	
28
	toPlural: function(){
29
		var word = this;
30
		
31
		// -ies  (study -> studies)
32
		if (word.endsWith("y") && word.length > 3) {
33
			return word.removePostfix("y") + "ies";
34
		}
35
		
36
		// -s  (dog -> dogs)
37
		return word + "s";
38
	},
39
40
	toSingular: function(){
41
		var word = this;
42
		
43
		// -ies  (studies -> study)
44
		if (word.endsWith("ies") && word.length > 3) {
45
			return word.removePostfix("ies") + "y";
46
		}
47
		
48
		// -s  (dogs -> dog)
49
		return word.removePostfix("s");
50
	},
51
	
52
	none:null
53
};
54
55
// register funcs
56
UB.registerFuncs(String.prototype, stringFuncs);